<!--项目（合同）月数据列表页-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 避免IE使用兼容模式 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="renderer" content="webkit">
<!-- TopJUI框架样式 -->
<link type="text/css" href="../../general/topjui/themes/default/topjui.core.min.css" rel="stylesheet">
<link type="text/css" href="../../general/topjui/themes/default/topjui.blue.css" rel="stylesheet" id="dynamicTheme" />
<!-- FontAwesome字体图标 -->
<link type="text/css" href="../../general/static/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
<!-- layui框架样式 -->
<link type="text/css" href="../../general/static/plugins/layui/css/layui.css" 	rel="stylesheet" />
<!-- jQuery相关引用 -->
<script type="text/javascript" src="../../general/static/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../../general/static/plugins/jquery/jquery.cookie.js"></script>
<!-- TopJUI框架配置 -->
<script type="text/javascript" src="../../general/static/public/js/topjui.config.js"></script>
<!-- TopJUI框架核心-->
<script type="text/javascript" src="../../general/topjui/js/topjui.core.min1.js"></script>
<!-- TopJUI中文支持 -->
<script type="text/javascript" src="../../general/topjui/js/locale/topjui.lang.zh_CN.js"></script>
<!-- layui框架js -->
<script type="text/javascript" src="../../general/static/plugins/layui/layui.js" charset="utf-8"></script>

<!--自定义的样式-->
<link type="text/css" href="../a_allcommon/all.css" 	rel="stylesheet" />

</head>
<body>
	<div class="page_box">
		<!--原查询区div开始-->
		<!-- <div class="query_box">
			<span style="padding: 10px;"></span>
			<a href="javascript:void(0)" data-toggle="topjui-menubutton"
			data-options="iconCls: 'fa fa-plus',btnCls:'topjui-btn-blue'" onclick="openAddDiag()">新增</a>
			<span style="padding: 50px;"></span>
			<form id="queryForm">
				项目名称：
				<input type="text" name="q_m_xiangmu_name" data-toggle="topjui-textbox"
					data-options="id:'q_m_xiangmu_name',prompt:'请输入项目名称',width:150">
				<span style="padding: 5px;"></span>
				开始时间：
				<input type="text" name="q_start_time" data-toggle="topjui-datebox" 
					data-options="id:'q_start_time',prompt:'请选择开始时间',width:200">
				<span style="padding: 5px;"></span>
				截止时间：
				<input type="text" name="q_end_time" data-toggle="topjui-datebox" 
					data-options="id:'q_end_time',prompt:'请选择截止时间',width:200">
				<span style="padding: 5px;"></span>
				<a href="javascript:doSubmit(1,20)" data-toggle="topjui-menubutton"
					 data-options="iconCls:'fa fa-search',btnCls:'topjui-btn-blue'">查询</a> 
			</form>
		</div> -->
		<!--原查询区div结束-->
		
		<!--新查询区div开始-->
		<div class="qb_div">
			<div class="qb_div_LR"> <!--新增区域（便于输入，提前赋值）-->
				<div class="lineAll line1">
					<span style="padding: 30px;"></span>
					项目(合同)月数据固定信息：
					<span style="padding: 10px;"></span>
					<a href="javascript:void(0)" data-toggle="topjui-menubutton"
					   data-options="iconCls: 'fa fa-plus',btnCls:'topjui-btn-blue'" 
						 onclick="openAddDiag()">新增</a>
				</div>
				<div class="lineAll">
					<div class="lineL">年月：</div>
					<div class="lineR">
					  <input type="text" name="i_shijian"
					         data-toggle="topjui-datebox" 
					  			 data-options="id:'i_shijian',prompt:'请选择年月',width:200">
					</div>
					<div class="lineL">工作日天数：</div>
					<div class="lineR">
						<input id="i_gongzuori" type="text" name="i_gongzuori"
						       data-toggle="topjui-numberbox"
						       data-options="prompt:'请输入当月工作日天数',min:0,precision:1,width:150">
					</div>
				</div>
				<div class="lineAll"></div>
			</div>
			<div class="qb_div_LR"> <!--原先的条件查询区域-->
				<div class="lineAll line1">
					<span style="padding: 5px;"></span>
					表格条件查询部分：
					<span style="padding: 10px;"></span>
					<a href="javascript:doSubmit(1,20)" data-toggle="topjui-menubutton"
						 data-options="iconCls:'fa fa-search',btnCls:'topjui-btn-blue'">查询</a>
				</div>
				<div class="lineAll">
					<div class="lineL">项目名称：</div>
					<div class="lineR">
						<input id="q_m_xiangmu_name" type="text" name="q_m_xiangmu_name" 
						       data-toggle="topjui-textbox"
						       data-options="prompt:'项目名称'">
					</div>
					<div class="lineL">开始时间：</div>
					<div class="lineR line2R">
						<input type="text" name="q_start_time" data-toggle="topjui-datebox"
							data-options="id:'q_start_time',prompt:'请选择开始时间',width:125">
					</div>
					<div class="lineL">截止时间：</div>
					<div class="lineR line2R">
						<input type="text" name="q_end_time" data-toggle="topjui-datebox"
							data-options="id:'q_end_time',prompt:'请选择截止时间',width:125">
					</div>
				</div>
			</div>
			
		</div>
		<!--新查询区div结束-->
		
		<div class="grid_box">
			<!-- datagrid表格（fitColumns:true表示限制滚动条，fitColumns:false表示允许滚动条）-->
			<table data-toggle="topjui-datagrid" class="productDg1" 
			       data-options="id:'b_ht_mTable',fitColumns:false,remoteSort:false,rownumberWidth:39">
				<thead>
					<tr>
						<th data-options="field:'m_xiangmu_name',title:'项目名称',sortable:true,width:300,align:'center'"></th>
						<th data-options="field:'m_shijian',title:'年月',formatter:fmt_riqi,sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_gongzuori',title:'工作日数',sortable:true,width:80,align:'center'"></th>
						<th data-options="field:'m_hetongfei',title:'合同额(元)',sortable:true,width:120,align:'center'"></th>
						<th data-options="field:'m_wuyefei',title:'物业费(元)',sortable:true,width:120,align:'center'"></th>
						<th data-options="field:'m_canfei',title:'餐费(元)',sortable:true,width:120,align:'center'"></th>
						<th data-options="field:'m_jihuawai_canbu',title:'计划外收入<br>餐补(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_jihuawai_hetongwai',title:'计划外收入<br>合同外(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_shuifei',title:'税费(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_gongzi',title:'工资(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_shebao',title:'保险<br>社保(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_shangbao',title:'保险<br>商保(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_gongjijin',title:'公积金(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_jiaotongfei',title:'交通费(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_shicai',title:'食材(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_haocai',title:'耗材(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_wuyezhichu',title:'物业支出(元)',sortable:true,width:120,align:'center'"></th>
						<th data-options="field:'m_jihuawai_suiqing',title:'计划外支出<br>碎请(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_jihuawai_weixiu',title:'计划外支出<br>维修(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_jihuawai_yanqing',title:'计划外支出<br>宴请(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_jihuawai_jiaxu',title:'计划外支出<br>甲需(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_shichangjingyingfei',title:'市场经营费(元)',sortable:true,width:120,align:'center'"></th>
						<th data-options="field:'m_fupin_832fupin',title:'扶贫<br>832扶贫(元)',sortable:true,width:110,align:'center'"></th>
						<th data-options="field:'m_fupin_shangwuju',title:'扶贫<br>商务局(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_fupin_dingxiang',title:'扶贫<br>定向(元)',sortable:true,width:100,align:'center'"></th>
						<th data-options="field:'m_lirun',title:'利润(元)',sortable:true,width:120,align:'center'"></th>
						<th data-options="field:'operate',title:'操作',formatter:operateFormatter,width:100,align:'left'"></th>
					</tr>
				</thead>
			</table>
		</div> <!--表格区div结束-->
		
	</div>
<script>
var HTMC_LIST=[]; //用于保存字典中项目名称下拉框的数据
$(function(){
	riqi_YM("#i_shijian");
	riqi_YM("#q_start_time");
	riqi_YM("#q_end_time");
	
	getA_ZDList("项目名称"); //取字典中项目名称集合
	doSubmit(1,20);//获取项目（合同）月数据表格数据
});
//根据键名取字典中的键值列表（用于填充项目名称、结款方式、验收人、这三个选择下拉）
function getA_ZDList(zidian_name){
	var formData={};
	formData.zidian_name=zidian_name;
	$.ajax({
		url:"/a_ZD/getA_ZDList",
		dataType:"JSON",
		type:"POST",
		data:formData,
		success:function(data){
			console.log("获取字典中键名为"+zidian_name+"的键值集合返回值data.rows==",data.rows);
			if(zidian_name=="项目名称"){
				HTMC_LIST=data.rows;
			}
		}
	});
}
//处理日期控件只显示“yyyy-MM”
function riqi_YM(inputId){
	$(inputId).datebox({
		onShowPanel : function() {// 显示日趋选择对象后再触发弹出月份层的事件，初始化时没有生成月份层
			span.trigger('click'); // 触发click事件弹出月份层
			if (!tds)
				setTimeout(function() {// 延时触发获取月份对象，因为上面的事件触发和对象生成有时间间隔
					tds = p.find('div.calendar-menu-month-inner td');
					tds.click(function(e) {
						e.stopPropagation(); // 禁止冒泡执行easyui给月份绑定的事件
						var year = /\d{4}/.exec(span.html())[0]// 得到年份
						, month = parseInt($(this).attr('abbr'), 10) + 1; // 月份
						$(inputId).datebox('hidePanel')// 隐藏日期对象
						.datebox('setValue', year + '-' + month); // 设置日期的值
					});
				}, 0);
		},
		parser : function(s) {// 配置parser，返回选择的日期
			if (!s)
				return new Date();
			var arr = s.split('-');
			return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
		},
		formatter : function(d) {
			if (d.getMonth() == 0) {
				return d.getFullYear()-1 + '-' + 12;
			} else {
				var tm=d.getMonth();
				if(tm<10){
					return d.getFullYear() + '-0' + d.getMonth();
				}else{
					return d.getFullYear() + '-' + d.getMonth();
				}
			}
		}// 配置formatter，只返回年月
	});
	var p = $(inputId).datebox('panel'), // 日期选择对象  '#'+inputId+''
	tds = false, // 日期选择对象中月份
	span = p.find('span.calendar-text'); // 显示月份层的触发控件
}
//根据项目（合同）名称、年月、当月工作日天数进行项目相关数据的获取与计算
function jisuan_xiangmu(ht_xiangmu_name,m_time,m_gongzuori){
	if(ht_xiangmu_name==""){
		$.iMessager.alert('警告', '请选择项目（合同）名称！', 'messager-warning');
		return;
	}
	if(m_time==""){ //日期格式已经处理为 “年月-01”的格式了
		$.iMessager.alert('警告', '请选择年月！', 'messager-warning');
		return;
	}else{
		m_time=m_time+" 00:00:00"; //处理为 “年月-01 00:00:00”的格式
	}
	if(m_gongzuori==""){
		$.iMessager.alert('警告', '请输入本月工作日天数！', 'messager-warning');
		return;
	}
	var formData={};
	formData.ht_xiangmu_name=ht_xiangmu_name;
	formData.m_time=m_time;
	formData.m_gongzuori=m_gongzuori;
	formData.pageIndex=1;
	formData.pageSize=1000;
	$.ajax({
		url:"/b_HT_M/jisuan_xiangmu",
		dataType:"JSON",
		type:"POST",
		data:formData,
		success:function(data){
			console.log("计算项目基础数据的返回值data==",data);
			if(data.status=="success"){
				//将返回值中计算出的数据给合同额、餐费、物业费、税费这4个控件赋值
				$('#m_hetongfei').iNumberbox('setValue', data.m_hetongfei);
				$('#m_wuyefei').iNumberbox('setValue', data.m_wuyefei);
				$('#m_canfei').iNumberbox('setValue', data.m_canfei);
				$('#m_shuifei').iNumberbox('setValue', data.m_shuifei);
				
				//进行薪资相关计算
				jisuan_gongzi(ht_xiangmu_name,m_time);
			}
			if(data.status=="error"){
				$.iMessager.alert('警告', data.message, 'messager-warning');
				return;
			}
		}
	});
}
//根据项目（合同）名称、年月进行该项目薪资数据的获取与计算
function jisuan_gongzi(ht_xiangmu_name,m_time){
	m_time=m_time.substr(0,7)+"-15 00:00:00";
	//var gz_xiangmu_name=
	var formData={};
	formData.m_time=m_time;
	formData.gz_xiangmu_name=ht_xiangmu_name;
	$.ajax({
		url:"/b_HT_M/jisuan_gongzi",
		dataType:"JSON",
		type:"POST",
		data:formData,
		success:function(data){
			console.log("计算项目薪资数据的返回值data==",data);
			if(data.status=="success"){
				//将返回值中计算出的数据给工资、社保、商保、公积金这4个控件赋值，外加1个交通费的固定值50
				if(data.rows==null){
					$('#m_gongzi').iNumberbox('setValue', 0);
					$('#m_shebao').iNumberbox('setValue', 0);
					$('#m_shangbao').iNumberbox('setValue', 0);
					$('#m_gongjijin').iNumberbox('setValue', 0);
				}else{
					$('#m_gongzi').iNumberbox('setValue', data.rows[0].total_gz_gongzi);
					$('#m_shebao').iNumberbox('setValue', data.rows[0].total_gz_bx_shebao);
					$('#m_shangbao').iNumberbox('setValue', data.rows[0].total_gz_bx_shangbao);
					$('#m_gongjijin').iNumberbox('setValue', data.rows[0].total_gz_gongjijin);
				}
				
				$('#m_jiaotongfei').iNumberbox('setValue', 50);
				//进行台账相关计算
				jisuan_taizhang(ht_xiangmu_name,m_time);
			}
			if(data.status=="error"){
				$.iMessager.alert('警告', data.message, 'messager-warning');
				return;
			}
		}
	});
}
//根据项目（合同）名称、年月进行该项目台账数据的获取与计算
function jisuan_taizhang(ht_xiangmu_name,m_time){
	var formData={};
	formData.m_time=m_time;
	formData.tz_xiangmu_name=ht_xiangmu_name;
	$.ajax({
		url:"/b_HT_M/jisuan_taizhang",
		dataType:"JSON",
		type:"POST",
		data:formData,
		success:function(data){
			console.log("计算项目台账统计数据的返回值data==",data);
			if(data.status=="success"){
				//将返回值中计算出的数据给食材统计数据、耗材统计数据、物业支出统计数据
				 $('#m_haocai').iNumberbox('setValue', data.m_haocai);
				 $('#m_wuyezhichu').iNumberbox('setValue', data.m_wuyezhichu);
				 $('#m_shicai').iNumberbox('setValue', data.m_shicai);
			}
			if(data.status=="error"){
				$.iMessager.alert('警告', data.message, 'messager-warning');
				return;
			}
		}
	});
}

//计算最终的利润，计算公式如下：
//合同额（物业费+餐费）+餐补+合同外-税费-工资-社保-商保-公积金-交通费-食材-耗材-物业支出-碎请-(维修)-宴请-甲需-市场经营费-832扶贫-商务局-定向
function jisuan_lirun(){
	var m_hetongfei=$('#m_hetongfei').iNumberbox('getValue'); //月均摊合同额
	if(m_hetongfei==""){m_hetongfei=0;}else{m_hetongfei=parseFloat(m_hetongfei);}
	//var m_wuyefei=$('#m_wuyefei').iNumberbox('getValue'); //物业费（月均摊）
	//var m_canfei=$('#m_canfei').iNumberbox('getValue'); //餐费（月均摊）
	var m_jihuawai_canbu=$('#m_jihuawai_canbu').iNumberbox('getValue'); //划外收入餐补
	if(m_jihuawai_canbu==""){m_jihuawai_canbu=0;}else{m_jihuawai_canbu=parseFloat(m_jihuawai_canbu);}
	var m_jihuawai_hetongwai=$('#m_jihuawai_hetongwai').iNumberbox('getValue'); //计划外收入合同外
	if(m_jihuawai_hetongwai==""){m_jihuawai_hetongwai=0;}else{m_jihuawai_hetongwai=parseFloat(m_jihuawai_hetongwai);}
	var m_shuifei=$('#m_shuifei').iNumberbox('getValue'); //税费
	if(m_shuifei==""){m_shuifei=0;}else{m_shuifei=parseFloat(m_shuifei);}
	var m_gongzi=$('#m_gongzi').iNumberbox('getValue'); //工资
	if(m_gongzi==""){m_gongzi=0;}else{m_gongzi=parseFloat(m_gongzi);}
	var m_shebao=$('#m_shebao').iNumberbox('getValue'); //社保
	if(m_shebao==""){m_shebao=0;}else{m_shebao=parseFloat(m_shebao);}
	var m_shangbao=$('#m_shangbao').iNumberbox('getValue'); //商保
	if(m_shangbao==""){m_shangbao=0;}else{m_shangbao=parseFloat(m_shangbao);}
	var m_gongjijin=$('#m_gongjijin').iNumberbox('getValue'); //公积金
	if(m_gongjijin==""){m_gongjijin=0;}else{m_gongjijin=parseFloat(m_gongjijin);}
	var m_jiaotongfei=$('#m_jiaotongfei').iNumberbox('getValue'); //交通费
	if(m_jiaotongfei==""){m_jiaotongfei=50;}else{m_jiaotongfei=parseFloat(m_jiaotongfei);}
	var m_shicai=$('#m_shicai').iNumberbox('getValue'); //食材
	if(m_shicai==""){m_shicai=0;}else{m_shicai=parseFloat(m_shicai);}
	var m_haocai=$('#m_haocai').iNumberbox('getValue'); //耗材
	if(m_haocai==""){m_haocai=0;}else{m_haocai=parseFloat(m_haocai);}
	var m_wuyezhichu=$('#m_wuyezhichu').iNumberbox('getValue'); //物业支出
	if(m_wuyezhichu==""){m_wuyezhichu=0;}else{m_wuyezhichum_wuyezhichu=parseFloat(m_wuyezhichu);}
	var m_jihuawai_suiqing=$('#m_jihuawai_suiqing').iNumberbox('getValue'); //计划外支出碎请
	if(m_jihuawai_suiqing==""){m_jihuawai_suiqing=0;}else{m_jihuawai_suiqing=parseFloat(m_jihuawai_suiqing);}
	var m_jihuawai_weixiu=$('#m_jihuawai_weixiu').iNumberbox('getValue'); //计划外支出维修
	if(m_jihuawai_weixiu==""){m_jihuawai_weixiu=0;}else{m_jihuawai_weixiu=parseFloat(m_jihuawai_weixiu);}
	var m_jihuawai_yanqing=$('#m_jihuawai_yanqing').iNumberbox('getValue'); //计划外支出宴请
	if(m_jihuawai_yanqing==""){m_jihuawai_yanqing=0;}else{m_jihuawai_yanqing=parseFloat(m_jihuawai_yanqing);}
	var m_jihuawai_jiaxu=$('#m_jihuawai_jiaxu').iNumberbox('getValue'); //计划外支出甲需
	if(m_jihuawai_jiaxu==""){m_jihuawai_jiaxu=0;}else{m_jihuawai_jiaxu=parseFloat(m_jihuawai_jiaxu);}
	var m_shichangjingyingfei=$('#m_shichangjingyingfei').iNumberbox('getValue'); //市场经营费
	if(m_shichangjingyingfei==""){m_shichangjingyingfei=0;}else{m_shichangjingyingfei=parseFloat(m_shichangjingyingfei);}
	var m_fupin_832fupin=$('#m_fupin_832fupin').iNumberbox('getValue'); //扶贫832扶贫
	if(m_fupin_832fupin==""){m_fupin_832fupin=0;}else{m_fupin_832fupin=parseFloat(m_fupin_832fupin);}
	var m_fupin_shangwuju=$('#m_fupin_shangwuju').iNumberbox('getValue'); //扶贫商务局
	if(m_fupin_shangwuju==""){m_fupin_shangwuju=0;}else{m_fupin_shangwuju=parseFloat(m_fupin_shangwuju);}
	var m_fupin_dingxiang=$('#m_fupin_dingxiang').iNumberbox('getValue'); //扶贫定向
	if(m_fupin_dingxiang==""){m_fupin_dingxiang=0;}else{m_fupin_dingxiang=parseFloat(m_fupin_dingxiang);}
	debugger;
	//利润计算公式
	//合同额（物业费+餐费）+餐补+合同外-税费-工资-社保-商保-公积金-交通费-食材-耗材-物业支出-碎请-(维修)-宴请-甲需-市场经营费-832扶贫-商务局-定向
	var m_lirun=m_hetongfei + m_jihuawai_canbu + m_jihuawai_hetongwai - m_shuifei - m_gongzi - m_shebao - m_shangbao - m_gongjijin -
	            m_jiaotongfei - m_shicai - m_haocai - m_wuyezhichu - m_jihuawai_suiqing - m_jihuawai_weixiu - m_jihuawai_yanqing - 
							m_jihuawai_jiaxu - m_shichangjingyingfei - m_fupin_832fupin - m_fupin_shangwuju - m_fupin_dingxiang; 
	$('#m_lirun').iNumberbox('setValue', m_lirun); //利润框赋值
}

//处理日期的显示
function fmt_riqi(value, row, index) {
	//debugger;
	var htmlstr ='';
	var a=value.substr(0,7);
	htmlstr+=a;
	return htmlstr;
}
//表头“操作”栏，formatter定义，这里面可以自定义按钮样式
function operateFormatter(value, row, index) {
	//debugger;
	var htmlstr ='';
	htmlstr += '<button class="layui-btn layui-btn-xs" onclick="openEditDiag(\''+row.id+'\')">编辑</button>';
	htmlstr += '<button class="layui-btn layui-btn-xs layui-btn-danger" onclick="deleteRow(\''+row.id+'\')">删除</button>';
	return htmlstr;
}

//新增项目（合同）月数据
function openAddDiag(){
	var formData={}; //b_ht_m_add.html
	var $addDialog = $('<form id="b_ht_mDg-add" style="width: 900px; height:850px; margin: auto; display: none;"></form>');
	var diag = $addDialog.dialog({
		title: '新建项目（合同）月数据',
		href: 'b_ht_m_add.html',
		modal: true,
		resizable:true,
		maximizable:true,
		collapsible:true,
		buttons:[{
			text:'保存',
			iconCls: 'fa fa-save',
			btnCls: 'topjui-btn-green',
			handler:function(){
				//验证框架（就是必填项必须要填）if开始			
				if($('#b_ht_mDg-add').form('validate')) {
					//提示框开始
					$.messager.confirm("操作提示", "确定新建此项目（合同）月数据吗？", function (data) {
						if(data){
							//提交代码块开始
							//debugger;
							var formData={};
							var m_xiangmu_id=$('#m_xiangmu_id').val(); //项目名称对应的字典id
							formData.m_xiangmu_id=m_xiangmu_id;
							
							var m_xiangmu_name=$('#m_xiangmu_name').iCombobox('getValue'); //项目名称 
							formData.m_xiangmu_name=m_xiangmu_name;
							
							var m_shijian=$('#m_shijian').iDatebox('getValue'); //项目（合同）月数据日期 
							m_shijian=m_shijian.substr(0,7); //截取前7位，格式为 "yyyy-MM"
							formData.m_shijian=m_shijian+"-01 00:00:00"; //规范为每月1日0时分秒
							
							var m_gongzuori=$('#m_gongzuori').iNumberbox('getValue'); //工作日天数
							formData.m_gongzuori=m_gongzuori;
							// if(m_gongzuori==""){
							// 	formData.m_gongzuori=21.5;
							// }else{
							// 	formData.m_gongzuori=m_gongzuori;
							// }
							
							var m_hetongfei=$('#m_hetongfei').iNumberbox('getValue'); //月均摊合同额
							formData.m_hetongfei=m_hetongfei;
							
							var m_wuyefei=$('#m_wuyefei').iNumberbox('getValue'); //物业费（月均摊）
							formData.m_wuyefei=m_wuyefei;
							
							var m_canfei=$('#m_canfei').iNumberbox('getValue'); //餐费（月均摊）
							formData.m_canfei=m_canfei;
							
							var m_jihuawai_canbu=$('#m_jihuawai_canbu').iNumberbox('getValue'); //划外收入餐补
							if(m_jihuawai_canbu==""){
								formData.m_jihuawai_canbu=0;
							}else{
								formData.m_jihuawai_canbu=m_jihuawai_canbu;
							}
							
							var m_jihuawai_hetongwai=$('#m_jihuawai_hetongwai').iNumberbox('getValue'); //计划外收入合同外
							if(m_jihuawai_hetongwai==""){
								formData.m_jihuawai_hetongwai=0;
							}else{
								formData.m_jihuawai_hetongwai=m_jihuawai_hetongwai;
							}
							
							var m_shuifei=$('#m_shuifei').iNumberbox('getValue'); //税费
							formData.m_shuifei=m_shuifei;
							
							var m_gongzi=$('#m_gongzi').iNumberbox('getValue'); //工资
							formData.m_gongzi=m_gongzi;
							
							var m_shebao=$('#m_shebao').iNumberbox('getValue'); //社保
							formData.m_shebao=m_shebao;
							
							var m_shangbao=$('#m_shangbao').iNumberbox('getValue'); //商保
							formData.m_shangbao=m_shangbao;
							
							var m_gongjijin=$('#m_gongjijin').iNumberbox('getValue'); //公积金
							formData.m_gongjijin=m_gongjijin;
							
							var m_jiaotongfei=$('#m_jiaotongfei').iNumberbox('getValue'); //交通费
							formData.m_jiaotongfei=m_jiaotongfei;
							
							var m_shicai=$('#m_shicai').iNumberbox('getValue'); //食材
							formData.m_shicai=m_shicai;
							
							var m_haocai=$('#m_haocai').iNumberbox('getValue'); //耗材
							formData.m_haocai=m_haocai;
							
							var m_wuyezhichu=$('#m_wuyezhichu').iNumberbox('getValue'); //物业支出
							formData.m_wuyezhichu=m_wuyezhichu;
							
							var m_jihuawai_suiqing=$('#m_jihuawai_suiqing').iNumberbox('getValue'); //计划外支出碎请
							if(m_jihuawai_suiqing==""){
								formData.m_jihuawai_suiqing=0;
							}else{
								formData.m_jihuawai_suiqing=m_jihuawai_suiqing;
							}
							
							var m_jihuawai_weixiu=$('#m_jihuawai_weixiu').iNumberbox('getValue'); //计划外支出维修
							if(m_jihuawai_weixiu==""){
								formData.m_jihuawai_weixiu=0;
							}else{
								formData.m_jihuawai_weixiu=m_jihuawai_weixiu;
							}
							
							var m_jihuawai_yanqing=$('#m_jihuawai_yanqing').iNumberbox('getValue'); //计划外支出宴请
							if(m_jihuawai_yanqing==""){
								formData.m_jihuawai_yanqing=0;
							}else{
								formData.m_jihuawai_yanqing=m_jihuawai_yanqing;
							}
							
							var m_jihuawai_jiaxu=$('#m_jihuawai_jiaxu').iNumberbox('getValue'); //计划外支出甲需
							if(m_jihuawai_jiaxu==""){
								formData.m_jihuawai_jiaxu=0;
							}else{
								formData.m_jihuawai_jiaxu=m_jihuawai_jiaxu;
							}
							
							var m_shichangjingyingfei=$('#m_shichangjingyingfei').iNumberbox('getValue'); //市场经营费
							if(m_shichangjingyingfei==""){
								formData.m_shichangjingyingfei=0;
							}else{
								formData.m_shichangjingyingfei=m_shichangjingyingfei;
							}
							
							var m_fupin_832fupin=$('#m_fupin_832fupin').iNumberbox('getValue'); //扶贫832扶贫
							if(m_fupin_832fupin==""){
								formData.m_fupin_832fupin=0;
							}else{
								formData.m_fupin_832fupin=m_fupin_832fupin;
							}
							
							var m_fupin_shangwuju=$('#m_fupin_shangwuju').iNumberbox('getValue'); //扶贫商务局
							if(m_fupin_shangwuju==""){
								formData.m_fupin_shangwuju=0;
							}else{
								formData.m_fupin_shangwuju=m_fupin_shangwuju;
							}
							
							var m_fupin_dingxiang=$('#m_fupin_dingxiang').iNumberbox('getValue'); //扶贫定向
							if(m_fupin_dingxiang==""){
								formData.m_fupin_dingxiang=0;
							}else{
								formData.m_fupin_dingxiang=m_fupin_dingxiang;
							}
							
							var m_lirun=$('#m_lirun').iNumberbox('getValue'); //利润
							formData.m_lirun=m_lirun;
							
							debugger;
							$.iMessager.progress({
								text: '正在操作...'
							});
							$.ajax({
								url:"/b_HT_M/insertB_HT_M",
								dataType:"JSON",
								type:"POST",
								data:formData,
								success:function(data){
									console.log("新增项目（合同）月数据返回值==",data);
									if(data.status=='success'){ 
										$.iMessager.show({title: '我的消息', msg: '操作成功', timeout: 2000, showType: 'slide'});// '消息窗口'组件
										//刷新表格数据采用主动请求的方式
										doSubmit(1,20);
										diag.dialog("destroy");// 销毁dialog面板
									}else{
										$.iMessager.show({title: '我的error消息', msg: data.message, timeout: 5000, showType: 'slide'});// '消息窗口'组件
									}
								},
								error:function(err){
									console.log("新增项目（合同）月数据接口错误==",err);
									$.iMessager.show({title: '接口错误消息', msg: err, timeout: 5000, showType: 'slide'});// '消息窗口'组件
								},
								complete:function(){
									$.iMessager.progress('close');//无论成功与否，都会关闭进度条；
								}
							}); //提交代码块结束
						}else {}
					});	//提示框结束
				} //验证框架（就是必填项必须要填）if结束		
			}
		},{
			text:'关闭',
			iconCls: 'fa fa-close',
			btnCls: 'topjui-btn-red',
			handler:function(){diag.dialog("destroy");}
		}],
		onClose: function () {
			$(this).dialog('destroy');//销毁
		},
		onLoad :function(){
			//1：加载项目名称下拉
			$('#m_xiangmu_name').iCombobox('loadData',HTMC_LIST); 
			
			//2：加载新补充的新增固定项（预置项）
			var i_shijian=$('#i_shijian').iDatebox('getValue'); //年月
			var i_gongzuori=$('#i_gongzuori').iNumberbox('getValue'); //工作日
			if(i_shijian != ""){
				i_shijian=i_shijian+"-01"; //处理为年月01日的格式
				$('#m_shijian').iDatebox('setValue',i_shijian); 
			}
			if(i_gongzuori != ""){
				$('#m_gongzuori').iNumberbox('setValue', i_gongzuori);
			}
		}
	});
	$addDialog.dialog('open');
}
//打开编辑页面
function openEditDiag(id){
	debugger;
	//先取实体对象
	$.ajax({
		url:"/b_HT_M/getB_HT_M",
		dataType:"JSON",
		type:"POST",
		data:{
			id:id,
		},
		success:function(data){
			debugger;
			openDialog(data.b_HT_M);//调用下面的用于回显的打开对话框函数
		}
	});
}
//再打开编辑对话框：由openEditDiag(id)函数末尾调用
function openDialog(d){
	debugger;
	var $updateDialog = $('<form id="b_ht_mDg-update"  style="width: 900px; height: 850px; margin: auto; display: none;"></form>');
	var diag = $updateDialog.dialog({
		title: '编辑项目（合同）月数据',
		href: 'b_ht_m_add.html',
		modal: true,
		resizable:true,
		maximizable:true,
		collapsible:true,
		//按钮定义
		buttons:[{
			text:'保存',
			iconCls: 'fa fa-save',
			btnCls: 'topjui-btn-green',
			handler:function(){
				if($('#b_ht_mDg-update').form('validate')){ //验证框架开始
					//提示框开始
					$.messager.confirm("操作提示", "确定编辑此项目（合同）月数据吗？", function (data) {
						if(data){
							//提交代码块开始
							var formData={};
							formData.id=d.id; //主键赋值
							
							var m_xiangmu_id=$('#m_xiangmu_id').val(); //项目名称对应的字典id
							formData.m_xiangmu_id=m_xiangmu_id;
							
							var m_xiangmu_name=$('#m_xiangmu_name').iCombobox('getValue'); //项目名称 
							formData.m_xiangmu_name=m_xiangmu_name;
							
							var m_shijian=$('#m_shijian').iDatebox('getValue'); //项目（合同）月数据日期 
							m_shijian=m_shijian.substr(0,7); //截取前7位，格式为 "yyyy-MM"
							formData.m_shijian=m_shijian+"-01 00:00:00"; //规范为每月1日0时分秒
							
							var m_gongzuori=$('#m_gongzuori').iNumberbox('getValue'); //工作日天数
							formData.m_gongzuori=m_gongzuori;
							// if(m_gongzuori==""){
							// 	formData.m_gongzuori=21.5;
							// }else{
							// 	formData.m_gongzuori=m_gongzuori;
							// }
							
							var m_hetongfei=$('#m_hetongfei').iNumberbox('getValue'); //月均摊合同额
							formData.m_hetongfei=m_hetongfei;
							
							var m_wuyefei=$('#m_wuyefei').iNumberbox('getValue'); //物业费（月均摊）
							formData.m_wuyefei=m_wuyefei;
							
							var m_canfei=$('#m_canfei').iNumberbox('getValue'); //餐费（月均摊）
							formData.m_canfei=m_canfei;
							
							var m_jihuawai_canbu=$('#m_jihuawai_canbu').iNumberbox('getValue'); //划外收入餐补
							if(m_jihuawai_canbu==""){
								formData.m_jihuawai_canbu=0;
							}else{
								formData.m_jihuawai_canbu=m_jihuawai_canbu;
							}
							
							var m_jihuawai_hetongwai=$('#m_jihuawai_hetongwai').iNumberbox('getValue'); //计划外收入合同外
							if(m_jihuawai_hetongwai==""){
								formData.m_jihuawai_hetongwai=0;
							}else{
								formData.m_jihuawai_hetongwai=m_jihuawai_hetongwai;
							}
							
							var m_shuifei=$('#m_shuifei').iNumberbox('getValue'); //税费
							formData.m_shuifei=m_shuifei;
							
							var m_gongzi=$('#m_gongzi').iNumberbox('getValue'); //工资
							formData.m_gongzi=m_gongzi;
							
							var m_shebao=$('#m_shebao').iNumberbox('getValue'); //社保
							formData.m_shebao=m_shebao;
							
							var m_shangbao=$('#m_shangbao').iNumberbox('getValue'); //商保
							formData.m_shangbao=m_shangbao;
							
							var m_gongjijin=$('#m_gongjijin').iNumberbox('getValue'); //公积金
							formData.m_gongjijin=m_gongjijin;
							
							var m_jiaotongfei=$('#m_jiaotongfei').iNumberbox('getValue'); //交通费
							formData.m_jiaotongfei=m_jiaotongfei;
							
							var m_shicai=$('#m_shicai').iNumberbox('getValue'); //食材
							formData.m_shicai=m_shicai;
							
							var m_haocai=$('#m_haocai').iNumberbox('getValue'); //耗材
							formData.m_haocai=m_haocai;
							
							var m_wuyezhichu=$('#m_wuyezhichu').iNumberbox('getValue'); //物业支出
							formData.m_wuyezhichu=m_wuyezhichu;
							
							var m_jihuawai_suiqing=$('#m_jihuawai_suiqing').iNumberbox('getValue'); //计划外支出碎请
							if(m_jihuawai_suiqing==""){
								formData.m_jihuawai_suiqing=0;
							}else{
								formData.m_jihuawai_suiqing=m_jihuawai_suiqing;
							}
							
							var m_jihuawai_weixiu=$('#m_jihuawai_weixiu').iNumberbox('getValue'); //计划外支出维修
							if(m_jihuawai_weixiu==""){
								formData.m_jihuawai_weixiu=0;
							}else{
								formData.m_jihuawai_weixiu=m_jihuawai_weixiu;
							}
							
							var m_jihuawai_yanqing=$('#m_jihuawai_yanqing').iNumberbox('getValue'); //计划外支出宴请
							if(m_jihuawai_yanqing==""){
								formData.m_jihuawai_yanqing=0;
							}else{
								formData.m_jihuawai_yanqing=m_jihuawai_yanqing;
							}
							
							var m_jihuawai_jiaxu=$('#m_jihuawai_jiaxu').iNumberbox('getValue'); //计划外支出甲需
							if(m_jihuawai_jiaxu==""){
								formData.m_jihuawai_jiaxu=0;
							}else{
								formData.m_jihuawai_jiaxu=m_jihuawai_jiaxu;
							}
							
							var m_shichangjingyingfei=$('#m_shichangjingyingfei').iNumberbox('getValue'); //市场经营费
							if(m_shichangjingyingfei==""){
								formData.m_shichangjingyingfei=0;
							}else{
								formData.m_shichangjingyingfei=m_shichangjingyingfei;
							}
							
							var m_fupin_832fupin=$('#m_fupin_832fupin').iNumberbox('getValue'); //扶贫832扶贫
							if(m_fupin_832fupin==""){
								formData.m_fupin_832fupin=0;
							}else{
								formData.m_fupin_832fupin=m_fupin_832fupin;
							}
							
							var m_fupin_shangwuju=$('#m_fupin_shangwuju').iNumberbox('getValue'); //扶贫商务局
							if(m_fupin_shangwuju==""){
								formData.m_fupin_shangwuju=0;
							}else{
								formData.m_fupin_shangwuju=m_fupin_shangwuju;
							}
							
							var m_fupin_dingxiang=$('#m_fupin_dingxiang').iNumberbox('getValue'); //扶贫定向
							if(m_fupin_dingxiang==""){
								formData.m_fupin_dingxiang=0;
							}else{
								formData.m_fupin_dingxiang=m_fupin_dingxiang;
							}
							
							var m_lirun=$('#m_lirun').iNumberbox('getValue'); //利润
							formData.m_lirun=m_lirun;
							
							debugger;
							$.iMessager.progress({
								text: '正在操作...'
							});
							$.ajax({
								url:"/b_HT_M/updateB_HT_M",
								dataType:"JSON",
								type:"POST",
								data:formData,
								success:function(data){
									console.log("编辑项目（合同）月数据返回值==",data);
									if(data.status=='success'){ 
										$.iMessager.show({title: '我的消息', msg: '操作成功', timeout: 2000, showType: 'slide'});// '消息窗口'组件
										//刷新表格数据采用主动请求的方式
										doSubmit(1,20);
										diag.dialog("destroy");// 销毁dialog面板
									}else{
										$.iMessager.show({title: '我的error消息', msg: data.message, timeout: 5000, showType: 'slide'});// '消息窗口'组件
									}
								},
								error:function(err){
									console.log("编辑项目（合同）月数据接口错误==",err);
									$.iMessager.show({title: '接口错误消息', msg: err, timeout: 5000, showType: 'slide'});// '消息窗口'组件
								},
								complete:function(){
									$.iMessager.progress('close');//无论成功与否，都会关闭进度条；
								}
							}); //提交代码块结束
						}else {}
					});	//提示框结束
				} //验证框架结束
			}
		},{
			text:'关闭',
			iconCls: 'fa fa-close',
			btnCls: 'topjui-btn-red',
			handler:function(){diag.dialog("destroy");}
		}], //按钮定义结束
		
		//对话框函数定义
		onClose: function () {
			$(this).dialog('destroy');//销毁
		},
		onLoad :function(){
			//1：加载项目名称下拉
			$('#m_xiangmu_name').iCombobox('loadData',HTMC_LIST); 
			//2：处理日期及工作日天数回显
			var m_shijian=d.m_shijian; //年月，格式为 "2024-10-01 00:00:00"
			m_shijian=m_shijian.substr(0,10); //截取前10位，格式为 "2024-10-01"
			$('#m_shijian').iDatebox('setValue',m_shijian);
			var m_gongzuori=d.m_gongzuori;
			$('#m_gongzuori').iNumberbox('setValue', m_gongzuori);
			//2：回显数据
			$('#b_ht_mDg-update').form('load',d);
			$('#m_shijian').iDatebox('setValue',m_shijian);
			$('#m_gongzuori').iNumberbox('setValue', m_gongzuori);
		}
	}); //dialog定义结束
	$updateDialog.dialog('open');
}
//删除合同（项目）
function deleteRow(id){
	//debugger;
	$.messager.confirm("操作提示", "是否删除本条项目（合同）月数据？", function (data) {
		if(data) {
			$.iMessager.progress({
				text: '正在操作...'
			});
			$.ajax({
				url:"/b_HT_M/delB_HT_M",
				dataType:"JSON",
				type:"POST",
				data:{
					"id":id,
				},
				success:function(data){
					console.log("删除项目（合同）月数据返回值==",data);
					if(data.status=='success'){ 
						$.iMessager.show({title: '我的消息', msg: '操作成功', timeout: 2000, showType: 'slide'});// '消息窗口'组件
						//刷新表格数据采用主动请求的方式
						doSubmit(1,20);
					}else{
						$.iMessager.show({title: '我的error消息', msg: data.message, timeout: 5000, showType: 'slide'});// '消息窗口'组件
					}
				},
				error:function(err){
					console.log("删除项目（合同）月数据接口错误==",err);
					$.iMessager.show({title: '接口错误消息', msg: err, timeout: 5000, showType: 'slide'});// '消息窗口'组件
				},
				complete:function(){
					$.iMessager.progress('close');//无论成功与否，都会关闭进度条；
				}
			}); 
		}else {}
	}); //提示框结束
}

/*************************************表格相关方法****************************************/
/********使用ajax返回的数据的方式加载表格（如下2个主要方法）*******/
//表格主查询（包含条件查询）
function doSubmit(pageIndex,pageSize){
	var formData={};
	formData.pageIndex=pageIndex;
	formData.pageSize=pageSize;
	//1：取查询参数 
	var q_m_xiangmu_name=$('#q_m_xiangmu_name').iTextbox('getValue').trim(); 
	if(q_m_xiangmu_name!=''){
		formData.m_xiangmu_name=q_m_xiangmu_name;
	}
	var q_start_time=$('#q_start_time').iDatebox('getValue');
	var q_end_time=$('#q_end_time').iDatebox('getValue');
	if(q_start_time!=''){
		formData.start_time=q_start_time+"-01 00:00:00";
	}
	if(q_end_time!=''){
		formData.end_time=q_end_time+"-28 00:00:00";
	}
	//验证结束时间不能早于开始时间
	if(q_start_time!='' && q_end_time!=''){
		var start=new Date(q_start_time);
		var end=new Date(q_end_time);
		if(end.getTime()<start.getTime()){
			$.iMessager.alert('警告', '结束时间不能早于开始时间！', 'messager-warning');
			return;
		}
	}
	debugger;
	//2：执行ajax查询请求
	$.ajax({
		url:"/b_HT_M/getB_HT_MList",
		dataType:"JSON",
		type:"POST",
		data:formData,
		success:function(data){
			console.log(data.rows);
			debugger;
			//3：fillDatagrid(data)函数加载表格
			fillDatagrid(data);//调用分页表格数据加载主函数
		}
	});
}

/********使用ajax返回的数据的方式加载表格（如下2个主要方法）*******/
//参数为ajax调用的返回值
function fillDatagrid(data){
	//第1步：取基础参数
	var rows=data.rows;
	var pageIndex=data.pageIndex;
	var pageSize=data.pageSize;
	//第2步：初始化表格
	$('#b_ht_mTable').datagrid({   
			url:null,
			data:data, //参数传过来的data就有了数据array，页码，页尺寸
			pagination:true,   
			pageSize:pageSize,   
			pageNumber:pageIndex,   
			rownumbers:true  
	});
	//第二步：再取分页对象，并定义点击分页按钮触发的事件（并使用自定义）
	$('#b_ht_mTable').datagrid('getPager').pagination({   
			onSelectPage : function(pPageIndex, pPageSize) {   
				//alert('页数:'+pPageIndex+',每页数据条数:'+pPageSize);
				doSubmit(pPageIndex,pPageSize);
			}   
	});
}
/********使用ajax返回的数据的方式加载表格（如上2个主要方法）*******/

</script>
</body>
</html>